//
//  DDEvaluateManager.m
//  Dingdong
//
//  Created by 程强 on 16/12/12.
//  Copyright © 2016年 程强. All rights reserved.
//

#import "DDEvaluateManager.h"

@implementation DDEvaluateManager
- (DSASubject *)evaluateGoods:(NSNumber *)goods_id content:(NSString *)content grade:(NSInteger)grade store_deliverycredit:(NSInteger)store_deliverycredit store_desccredit:(NSInteger)store_desccredit store_servicecredit:(NSInteger)store_servicecredit picnames:(NSString *)picnames
{
    DSASubject *subject = [DSASubject subject];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@wap/comment/add.do", ServerUrl];
    
    NSDictionary *body = @{@"goods_id":goods_id,@"commenttype":@"1",@"content":content,@"grade":@(grade),@"store_deliverycredit":@(store_deliverycredit),@"store_desccredit":@(store_desccredit),@"store_servicecredit":@(store_servicecredit),@"picnames":picnames};
    NSString *sign = [SystemConfig httpSignWithBody:body];
    
    [KKHttpServices httpPostUrl:doVerifyurl sign:sign prams:body success:^(id responseObject, KKHttpParse *parse) {
        NSDictionary *rdic = parse.responseJsonOB;
        [subject sendNext:rdic];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    } cancel:^(NSURLSessionDataTask *task) {
        __strong DSASubject *dsaSubject = subject;
        [subject setDispose:^{
            [task cancel];
            [dsaSubject sendCompleted];
        }];
    }];
    return subject;
}
- (DSASubject *)uploadEvaluatePics:(NSData *)pic picName:(NSString *)name
{
    DSASubject *subject = [DSASubject subject];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@wap/comment/imageUpload.do", ServerUrl];
    
    NSDictionary *body = nil;
    NSString *sign = [SystemConfig httpSignWithBody:body];
    
    [KKHttpServices postUploadFile:doVerifyurl sign:sign prams:nil thumbnail:pic thumname:name success:^(id responseObject, KKHttpParse *parse) {
        NSDictionary *rdic = parse.responseJsonOB;
        NSString *url = ValidString(rdic[@"data"]);
        [subject sendNext:url];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError* err = nil;
        [KKHttpServices creatHttpErr:parse err:&err];
        [subject sendError:err];
        [subject sendCompleted];
    } cancel:^(NSURLSessionDataTask *task) {
        __strong DSASubject *dsaSubject = subject;
        [subject setDispose:^{
            [task cancel];
            [dsaSubject sendCompleted];
        }];
    }];
    return subject;
}
@end
